package com.qf.contorller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.pojo.Cost;
import com.qf.service.CostService;
import com.qf.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zdl
 * @date 2025/2/15
 */
@RestController
@RequestMapping("/cost")
public class CostController {
    @Resource
    private CostService costService;
    @GetMapping("/all")
    public R<PageInfo<Cost>> findAllCost(@RequestParam int pageNum, @RequestParam int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Cost> allCost = costService.findAllCost();
        PageInfo<Cost> costPageInfo = new PageInfo<>(allCost);
        return R.ok(costPageInfo);
    }

    @PostMapping("/add")
    public R<Integer> addCost(@RequestBody Cost cost){
        return R.ok(costService.addCost(cost));
    }

    @GetMapping("/del/{cid}")
    public R<Integer> delCostByCid(@PathVariable("cid") int cid){
        return R.ok(costService.delCostByCid(cid));
    }

    @PostMapping("/update")
    public R<Integer> updateCost(@RequestBody Cost cost){
        return R.ok(costService.updateCostByCost(cost));
    }
}
